/*
 * @Author: Zyunchao 18651805393@163.com
 * @Date: 2022-07-13 10:52:21
 * @LastEditors: Zyunchao 18651805393@163.com
 * @LastEditTime: 2023-07-17 11:19:39
 * @FilePath: /micro-temp-monorepo/_core/microMain/setLocalStore.ts
 * @Description: 处理远程 vuex 数据的核心文件
 */
import store from '@jsjn/micro-core-store'
import { RootStateTypes } from '@jsjn/micro-core-store/interface/index'
import _ from 'lodash'
// import packInfo from '@ROOT/package.json'
// import { routeMode } from './routeMode'

const commitMapping = {
    // appFuncTree: 'appFuncTree/setAppFuncTreeStoreModule',
    // currentStatus: 'currentStatus/setCurrentStatusStoreModule',
    currentUserInfo: 'currentUserInfo/setCurrentUserInfo',
    loginInfo: 'loginInfo/setLoginInfo',
    sysDict: 'sysDict/setSysDictStoreModule',
    systemSafeInfo: 'systemSafeInfo/setSystemSafeInfo'
}

/**
 * 将本地的 vuex 的各模块全量赋值
 * @param vuex 接收的 vuex 的 state 对象
 * @returns
 */
export default function setLocalStore(vuex: RootStateTypes) {
    if (!vuex) return

    Object.keys(commitMapping).forEach((moduleName) => {
        store.commit(commitMapping[moduleName], vuex[moduleName])
    })

    /**
     * 远程的已注册的路由，包含
     *  - 基座
     *  - 当前微应用
     *  - 其他兄弟微应用
     */
    store.commit(
        'appFuncTree/setRemoteRegisteredRoutes',
        _.cloneDeep(vuex.appFuncTree.registeredRoutes)
    )

    // 屏幕比例（首页卡片）
    vuex.currentStatus.screenRatio &&
        store.commit('currentStatus/setScreenRatio', vuex.currentStatus.screenRatio)

    // 浏览器信息
    vuex.currentStatus.currentBrowser &&
        store.commit('currentStatus/setCurrentBrowser', vuex.currentStatus.currentBrowser)
}